// -*-java-*-

/**
 * Copyright 2010 Google Inc.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 **/

var BUZZ_PATH_REGEXP = /^\/buzz\/(\w{10,})(?:$|\.xml|\#|\/)/;

var pingUrlToGraphNode = function(url, host, path) {
  var m;
  if (m = BUZZ_PATH_REGEXP.exec(path)) {
    return "sgn://ping.fm/?pk=buzz" + m[1];
  }
  return url;
};

var sgnToHttpProfile = function (pk) {
  if (pk.substr(0, 4) == "buzz") {
    return "http://ping.fm/buzz/" + pk.substr(4);
  }
};

var sgnToHttpAtom = function (pk) {
  if (pk.substr(0, 4) == "buzz") {
    return "http://ping.fm/buzz/" + pk.substr(4) + ".xml";
  }
};

nodemapper.registerDomain(
    "ping.fm",
    { name: "Ping.fm",
      pkRegexp: /^buzz\w{10,}$/,  // maybe other types in future?
      identRegexp: /^$/,
      accountToSgn: {
        pk: ["ping.fm", /^buzz\w{10,}$/]
      },
      urlToGraphNode: pingUrlToGraphNode,
      pk_to_profile: sgnToHttpProfile,
      pk_to_atom: sgnToHttpAtom
    });

__END__

http://stage.ping.fm/buzz/JIqHIhDG8T1CWDduErJLjaU0YIFFm2MV sgn://ping.fm/?pk=buzzJIqHIhDG8T1CWDduErJLjaU0YIFFm2MV
http://ping.fm/buzz/JIqHIhDG8T1CWDduErJLjaU0YIFFm2MV sgn://ping.fm/?pk=buzzJIqHIhDG8T1CWDduErJLjaU0YIFFm2MV
http://ping.fm/buzz/JIqHIhDG8T1CWDduErJLjaU0YIFFm2MV/ sgn://ping.fm/?pk=buzzJIqHIhDG8T1CWDduErJLjaU0YIFFm2MV
http://ping.fm/buzz/JIqHIhDG8T1CWDduErJLjaU0YIFFm2MV# sgn://ping.fm/?pk=buzzJIqHIhDG8T1CWDduErJLjaU0YIFFm2MV
http://ping.fm/buzz/JIqHIhDG8T1CWDduErJLjaU0YIFFm2MV.xml sgn://ping.fm/?pk=buzzJIqHIhDG8T1CWDduErJLjaU0YIFFm2MV

atom(sgn://ping.fm/?pk=buzzJIqHIhDG8T1CWDduErJLjaU0YIFFm2MV) http://ping.fm/buzz/JIqHIhDG8T1CWDduErJLjaU0YIFFm2MV.xml
profile(sgn://ping.fm/?pk=buzzJIqHIhDG8T1CWDduErJLjaU0YIFFm2MV) http://ping.fm/buzz/JIqHIhDG8T1CWDduErJLjaU0YIFFm2MV

pair(ping.fm,buzzJIqHIhDG8T1CWDduErJLjaU0YIFFm2MV) sgn://ping.fm/?pk=buzzJIqHIhDG8T1CWDduErJLjaU0YIFFm2MV
